import axios from "@/utils/http";
//数据
const state = {
  //数据定义处
  tableData:[],
  tableTotal:1,
  tableData1:[],
  tableTotal1:1,

};

const getters = {
  //修饰后的数据获取方法
  getDicData(state:any){
    return state.tableData
  },
  getDicData1(state:any){
    return state.tableData1
  }
};

const mutations = {
  //修改数据处 ，可在这写axios请求拿数据
  // 分页获取全部数据
  setDicData(state:any,page:any){
    console.log(page);
    
    axios({
      url:"/setting/systemDrug/fundDrugs",
      method:"get",
      params:{
        currentPage:page.currentPage,
        pageSize:page.pageSize
      }
      }).then((res:any)=>{
          // state.XXX=res.data.data
          console.log("字典数据",res.data);
          state.tableData=res.data.data
          state.tableTotal=res.data.count
     }).catch(err=>{
      console.log(err);
     })
    
  },

  // 编辑数据接口
  editDicData(state:any,data:any){
    console.log("测试数据",data);
    
    axios({
      url:"/setting/systemDrug/editDrugs",
      method:"post",
      data:{
        id:data.drugId,
        drugRemark: data.drugRemark,
        drugUsage: data.drugUsage,
        durgSort: data.drugSort,
 
      }
      }).then((res:any)=>{
          console.log("编辑字典数据",res);     
     }).catch(err=>{
      console.log(err);
     })
  },

  // 删除数据
  delDicData(state:any,data:any){
    console.log(typeof data);
    
    axios({
      url:"/setting/systemDrug/deltDrugs",
      method:"post",
      params:{
        id:data
      }
      }).then((res:any)=>{
          console.log("删除数据",res);
     }).catch(err=>{
      console.log(err);
     })
  },

  // 增加数据接口
  addDicData(state:any,data:any){
    axios({
      url:"/setting/systemDrug/addDrugs",
      method:"post",
      data:{
        "drugId": data.drugId,
        "drugName":data.drugName,
        "drugUsage": data.drugUsage,
        "drugRemark": data.drugRemark,
        "durgSort": data.durgSort,
        "durgSource": "哈药集团",
        "drugNumber": 1006,
        "drugUnit": "g",
        "drugSpecification": data.drugSpecification,
        "drugFactory": "中央药厂",
        "createDate": "2022-11-22",
        "status": 0
      }
      }).then((res:any)=>{
          console.log("增加数据",res);
     }).catch(err=>{
      console.log(err);
     })
  },


  // 获取项目数据接口
  setDicProjectData(state:any){
    axios({
      url:"/setting/SystemInspection/fundprojectss",
      method:"get",
      params:{
        // currentPage:page.currentPage,
        // pageSize:page.pageSize
      }
      }).then((res:any)=>{
          // state.XXX=res.data.data
          console.log("新项目数据",res.data);
          state.tableData1=res.data.data
          console.log(typeof state.tableData1);
          
          state.tableTotal1=res.data.data.length
     }).catch(err=>{
      console.log(err);
     })
  },

// 新增项目成员接口
addDicProjectData(state:any,data:any){
  console.log(data,name);
  
  axios({
    url:"/setting/systemProject/addProject",
    method:"post",
    params:{
      projectName:data.name
    }
    }).then((res:any)=>{
        console.log("增加数据",res);
   }).catch(err=>{
    console.log(err);
   })
},

// 删除项目成员接口
delDicProjectData(state:any,data:any){
  axios({
    url:"/setting/systemProject/delProject",
    method:"post",
    params:{
      id:data.id
    }
    }).then((res:any)=>{
        console.log("删除数据",res);
   }).catch(err=>{
    console.log(err);
   })
},

// 编辑项目成员接口
editDicProjectData(state:any,data:any){
  axios({
    url:"/setting/systemProject/editProject",
    method:"post",
    data:{
      "id": data.id,
      "projectName": data.projectName,
      "projectRemark": "string",
      "projectSource": data.projectSource
    }
    }).then((res:any)=>{
        console.log("删除数据",res);
   }).catch(err=>{
    console.log(err);
   })
}

};

const actions = {};

export default {
  state,
  mutations,
  actions,
  getters,
};
